<?php
require dirname(__FILE__)."./dbconfig.php";
class db{
    public $conn=null;
    public $table="news";
    public function __construct($config){
        if(!empty($config)){
            $this->conn=mysqli_connect($config['host'],$config['username'],$config['password'],$config['database']) or die(mysqli_connect_error());//链接数据库
            mysqli_query($this->conn,"set names utf8") or die(mysqli_connect_error());                  //设定编码格式
        }    
    }
    public function getResult($sql){                                                                    //将sql语句查询到的信息依次赋值给res
        $resource=mysqli_query($this->conn,$sql) or die(mysqli_error($this->conn));
        $res=array();
        while(($row=mysqli_fetch_assoc($resource))!=false){
            $res[]=$row;
        }
        return $res;
    }
    public function getDataById($id){                                                                  //获取查询结果
        $sql="select * from news where id=".$id." order by id desc";
        $res=$this->getResult($sql);
        return $res;
    }
    
}

?>






